package domain.league;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import domain.tournament.DeathMatch;
import domain.tournament.FreePlay;
import domain.tournament.ITournament;
import domain.tournament.Tournament;
import domain.users.User;

public class League implements ILeague, Serializable  {

	private static final long serialVersionUID = 6308257982029190133L;
	private String title;
	private List<ITournament> tournaments;
	private User user;
	
	public League(String title, User user) {
		this.title = title;
		this.user = user;
		//Dummy Data.
		tournaments = new ArrayList<ITournament>();
		tournaments.add(new FreePlay(tournaments.size(),"Offical Free-Play Tournament", user, 64));
		tournaments.add(new DeathMatch(tournaments.size(),"Offical DeathMatch Tournament", user, 64));
	}

	public List<ITournament> getTournaments() {
		return tournaments;
	}
	
	@Override
	public int getNumTournamentsInLeague() {
		return tournaments.size();
	}
	
	@Override
	public String toString() {
		return title + " (" + tournaments.size() + " tournaments)";
	}


	@Override
	public String getTitle() {
		return title;
	}


	@Override
	public void addTournamentToLeague(Tournament tournament) {
		tournaments.add(tournament);
	}


	@Override
	public void deleteTournamentFromLeague(Tournament tournament) {
		for(int i = 0; i < tournaments.size(); i++){
			ITournament iTournament = tournaments.get(i);
			if (tournament.equals(iTournament)) {
				tournament = null;
			} else {
				System.out.println("Tournament does not exist.");
			}
		}
		
	}

	@Override
	public User getUser() {
		return user;
	}
		
}
